package com.lottery.ruok.lottrey.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.lottery.ruok.lottrey.R;
import com.lottery.ruok.lottrey.retrofitModule.response.RechargeLogResponse;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by ASUS on 2017/11/8.
 */

public class ChargeRecordAdapter extends BaseAdapter {
    private Context mContext;
    private RechargeLogResponse rechargeLogResponse;
    public ChargeRecordAdapter(RechargeLogResponse rechargeLogResponse, Context context) {
        mContext = context;
        this.rechargeLogResponse = rechargeLogResponse;
    }

    public void setDatas(RechargeLogResponse rechargeLogResponse){
        this.rechargeLogResponse = rechargeLogResponse;
    }

    @Override
    public int getCount() {
        return rechargeLogResponse.getList().size();
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder;
        if (view != null) {
            holder = (ViewHolder) view.getTag();
        } else {
            view = LayoutInflater.from(mContext).inflate(R.layout.charge_log_child_item, viewGroup, false);
            holder = new ViewHolder(view);
            view.setTag(holder);
        }
        holder.time.setText(rechargeLogResponse.getList().get(i).getSubmit_time());
        int color;
        switch (rechargeLogResponse.getList().get(i).getType4_desc()) {
            case "待审核":
            case "待支付":
                color = Color.parseColor("#d8971d");
                break;
            case "已审核":
                color = Color.parseColor("#989898");
                break;
            case "拒绝":
                color = Color.parseColor("#f45300");
                break;
            case "异常":
                color = Color.parseColor("#661dac");
                break;
            default:
                color = Color.parseColor("#3f3f3f");
                break;
        }
        holder.condition.setText(rechargeLogResponse.getList().get(i).getType4_desc());
        holder.condition.setTextColor(color);
        holder.content.setText(rechargeLogResponse.getList().get(i).getType3() + rechargeLogResponse.getList().get(i).getAmount() + "元");

        return view;
    }

    static class ViewHolder {
        @BindView(R.id.time)
        TextView time;
        @BindView(R.id.content)
        TextView content;
        @BindView(R.id.condition)
        TextView condition;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}